'use strict';

const fs = require('fs');
const path = require('path')

// Yes, could look for BUILD files also, but wait for that error to
// occur before fixing it.
visitSync('node_modules/', filename => {
  if (filename.endsWith("BUILD.bazel")) {
    fs.unlink(filename);
    console.log("Removed", filename, "from the node_modules/ tree");
  }
});

function visitSync(d, visitFn) {
  if (fs.statSync(d).isDirectory()) {
    fs.readdirSync(d).forEach(name => visitSync(path.join(d, name), visitFn));
  } else {
    visitFn(d);
  }                             
}
          
          
